/* 
 Created on : 2015-1-28, 16:18:09
  songshuai@foxmail.com
 */
 
var 
jcookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
 

var h = new function () {

    this.fenxiang = function () {
        /*
         h.app_api('orpheus://share/%E8%BF%99%E7%A7%91%E5%AD%A6%E5%90%97%EF%BC%9F%E6%88%91%E5%9C%A8%23%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90%23%E7%9A%84%E5%90%AC%E6%AD%8C%E5%8F%A3%E5%91%B3%E7%AB%9F%E7%84%B6%E6%98%AF%E2%80%9C%E6%97%A5%E8%92%B2%E5%A4%9C%E8%92%B2%E7%9A%84%E5%90%8E%E7%94%9F%E4%BB%94%E2%80%9D%EF%BC%81%E7%9C%8B%E7%9C%8B%E4%BD%A0%E7%9A%84%E6%BD%9C%E5%9C%A8%E5%90%AC%E6%AD%8C%E5%8F%A3%E5%91%B3%E6%9C%89%E5%A4%9A%E6%83%8A%E4%BA%BA%EF%BC%9F%E7%8C%9B%E6%88%B3%E8%BF%99%E9%87%8C~/http%3A%2F%2Fp2.music.126.net%2Fvy1UhNmYqOV7dJ2zYf7G9g%3D%3D%2F2053887720719921.jpg/http%3A%2F%2Figame.163.com%2Ftaste%2Fresult%3Fid%3D30%26userId%3D744019/%E8%BF%99%E7%A7%91%E5%AD%A6%E5%90%97%EF%BC%9F%E6%88%91%E7%9A%84%E5%90%AC%E6%AD%8C%E5%8F%A3%E5%91%B3%E7%AB%9F%E7%84%B6%E6%98%AF%E2%80%9C%E6%97%A5%E8%92%B2%E5%A4%9C%E8%92%B2%E7%9A%84%E5%90%8E%E7%94%9F%E4%BB%94%E2%80%9D%EF%BC%81');
         alert("修改后");
         return false;
         */
        h.app_api('orpheus://share/' +
                encodeURIComponent(share.title) + ////分享文案
                '/' + encodeURIComponent(share.img) + ///分享的图片URL
                '/' + encodeURIComponent(share.url) + ///跳转链接
                '/' + encodeURIComponent(share.title) + ////分享标题
                '/' + encodeURIComponent(share.desc)
                );
        //  alert(yixin_weixin);

        return false;
    };

    this.app_api = function (url) {
        var iFrame;
        iFrame = document.createElement("iframe");
        iFrame.setAttribute("src", url);
        iFrame.setAttribute("style", "display:none;");
        iFrame.setAttribute("height", "0px");
        iFrame.setAttribute("width", "0px");
        iFrame.setAttribute("frameborder", "0");
        document.body.appendChild(iFrame);
        iFrame.parentNode.removeChild(iFrame);
        iFrame = null;
    };


    /**
     * 分享被调用
     * */
    this.on_share=function(type){
       // alert(type);
        if(typeof(_hmt)=='object'&&typeof(_hmt.push)=='function'){
             _hmt.push(['_trackEvent','on_share'+type+share.get_type, 'share',type]);
        }
    };


};


var sh = new function () {

    this.open = function (str) { 
            window.open(str);
      
    };

    /**
     * 人人
     */
    this.renren = function () {
        var sha = shareData;
        sh.open('http://widget.renren.com/dialog/share?title=' + encodeURIComponent(sha.tTitle)
                + '&description=' + encodeURIComponent(sha.tContent)
                + '&resourceUrl=' + encodeURIComponent(sha.weiboLink) + '&srcUrl=' + encodeURIComponent(sha.weiboLink)

                + '&pic=' + sha.fImgUrl
                );
    };


    /**
     * 分享微博
     */
    this.weibo = function () {
        var sha = shareData;
        sh.open('http://v.t.sina.com.cn/share/share.php?title=' + encodeURIComponent(sha.tTitle)
                + '&url=' + encodeURIComponent(sha.weiboLink) +
                '&pic=' + sha.fImgUrl
                );
    };

    /**
     * 豆瓣
     */
    this.douban = function () {
        var sha = shareData;
        sh.open('http://www.douban.com/share/service?title=' + encodeURIComponent(sha.tTitle)
                + '&name=' + encodeURIComponent(sha.tContent)
                + '&href=' + encodeURIComponent(sha.weiboLink)
                ///   + '&href='+encodeURIComponent('http://final_bd.163.com/home/i/share/kid/bc59a7ca11fa.html') 

                + '&image=' + encodeURIComponent(sha.fImgUrl)
                );
    };
     
 
};



var iframe_wc = false;
/**
 * iframe加载完成后调用,
 */
function iframe_load() {
    // alert('ddddddddd');
    iframe_wc = true;
    post_cookie_music_u();
}



var PROXY_IF;
var login_music_u = 'no';
var post_er = 2;
function post_cookie_music_u() {

    if (login_music_u === true || login_music_u === 'load')
        return;

    document.domain = 'music.163.com';

    var js_bq = document.getElementById('proxy').contentWindow.document.createElement("script");//src
    js_bq.setAttribute('type', 'text/javascript');
    js_bq.setAttribute('charset', 'utf-8');
    js_bq.setAttribute('src', 'http://' + location.host + '/public/iframe.js');
    var body = document.getElementById('proxy').contentWindow.document.getElementsByTagName('body');
    body[0].appendChild(js_bq);
    document.getElementById('proxy').contentWindow.document.fun_return = function (data) {
        if (login_music_u === true || login_music_u === 'load')
            return;
        if (typeof (data) == 'object' && data.uid != 0 && data.createTime > 10) {
            login_music_u = 'load';
            home.user = data;
            ///    alert(data.nickname);
            sys.post('/api/login.html', data, function (d) {
                login_music_u = true;

            });
        } else {
            login_music_u = false;
            if (post_er > 0) {
                post_cookie_music_u();///再调用一次
            } else {
                //  alert('接口调用失败');
            }
            post_er--;
        }
    };

    /// login_music_u=true;   sys.post('/api/login.html',{music_u:music_u},function(d){  });
}
;

var sys = null;
//var sys = new function () {
function H_FUN() {
    this.post = function (url, par, fun, msg) {
        if (typeof (msg) != 'string' || msg == '') {
            msg = "操作成功";
        }
        if (typeof (fun) != 'function') {
            fun = function (data) {
             //   alert(msg);
            };
        }
        
        if(typeof(WEB)=='string'){
            url=WEB+url;
        }
        
        if($('[name=csrf-token]')[0]){
            par['_csrf']=$('[name=csrf-token]').attr('content');
        }
        
        $.post(url, par, function (data) {
            if (data.code != 0) {
                alert(data.data);
                return;
            } else {
                fun(data);
            }
        }, 'json');
    };
    
     this.post_error_msg=function(msg){
        sys.post('/home/i/msg',{msg:msg});
    };

};
sys = new H_FUN();


 